﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STDTO.DataTransferObjects.Unit.Tests.Interfaces;
using STDTO.DataTransferObjects.Interfaces;
using System.Runtime.Serialization;
using Microsoft.Practices.Unity;

namespace STDTO.DataTransferObjects.Unit.Tests.DTOs
{
    [DataContract]
    public class SimpleObjectDeriveDto : SimpleObjectDto, IDeriveFromSimpleObject, ISelfTrackingDataTransferObjectEx<IDeriveFromSimpleObject>
    {
        public SimpleObjectDeriveDto(IUnityContainer unityContainer) : base(unityContainer) { }
        [DataMember]
        private string _ExtProperty;

        public string ExtProperty
        {
            get
            {
                return _ExtProperty;
            }
            set
            {
                Set("ExtProperty", ref _ExtProperty, value);
            }
        }


        #region ISelfTrackingDataTransferObjectEx<ISimpleObjectDerive> Members

        public void Populate(IDeriveFromSimpleObject entity, IDataTrasferObjectToEntityMapper entityMapper)
        {
            base.Populate(entity, entityMapper);
            _ExtProperty = entity.ExtProperty;

        }

        public new IDeriveFromSimpleObject Clone(bool getOriginalValue, IDataTrasferObjectToEntityMapper entityMapper)
        {
            IDeriveFromSimpleObject res=  base.Clone(getOriginalValue, entityMapper) as IDeriveFromSimpleObject;
            res.ExtProperty = ExtProperty;
            return res;
        }

        public void ApplyChanges(IDeriveFromSimpleObject enitity, IDataTrasferObjectToEntityMapper entityMapper)
        {
            base.ApplyChanges(enitity, entityMapper);
        }

        #endregion



        #region ISelfTrackingDataTransferObject<ISimpleObjectDerive> Members

        public void Populate(IDeriveFromSimpleObject entity)
        {
            IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper = GetDataTrasferObjectToEntityMapper();
            Populate(entity, dataTrasferObjectToEntityMapper);
        }

        public new IDeriveFromSimpleObject Clone(bool getOriginalValue)
        {
            IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper = GetDataTrasferObjectToEntityMapper();
            return Clone(getOriginalValue, dataTrasferObjectToEntityMapper);
        }

        public void ApplyChanges(IDeriveFromSimpleObject enitity)
        {
            IDataTrasferObjectToEntityMapper dataTrasferObjectToEntityMapper = GetDataTrasferObjectToEntityMapper();
            ApplyChanges(enitity, dataTrasferObjectToEntityMapper);
        }

        #endregion

        protected override ISimpleObject GetServerSideInstance()
        {
            return _unityContainer.Resolve<IDeriveFromSimpleObject>();
        }
    }
}
